package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.community.model.Department;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.privilege.model.Role;
import com.eling.elcms.privilege.model.User;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;

@Entity
@Indexed
@Table(name = "fp_approvaldefineitem")
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = OrderCriteriaEnhancer.class,parameter="sequenceNumber") })
public class ApprovalDefineItem extends BaseModel {

	private static final long serialVersionUID = -4115918962874572902L;

	@Id
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkApprovalDefineItem;

	/** 对应审批流程 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkApprovalDefine")
	private ApprovalDefine approvalDefine;

	/** 序号 */
	@Column
	@Field
	private Integer sequenceNumber;
	
	
	/** 审批规则 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkApprovalRuleRegister")
	private ApprovalRuleRegister approvalRuleRegister;
	
	/** 审批规则找到 */
	@Column
	@Field
	private String arrKeyValue;
	
	/** 审批规则找到 */
	@Column
	@Field
	private String arrValue;
	

	/** 审批方类型 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private AppSideType appsidetype;

	/** 审批方类型 */
	@JsonSerialize(using = EnumSerializer.class)
	public static enum AppSideType {
		Commiter("提交方"),Department("部门"), Role("角色"), Person("人");

		private String display;

		AppSideType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	/** 审批部门 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkDepartment")
	@IndexedEmbedded(depth = 1)
	private Department approvalDepartment;

	/** 审批角色 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkRole")
	@IndexedEmbedded(depth = 1)
	private Role approvalRole;

	/** 审批人 */
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name = "pkUser")
	@IndexedEmbedded(depth = 1)
	private User approvalUser;

	@Version
	private Integer version;

	public Long getPkApprovalDefineItem() {
		return pkApprovalDefineItem;
	}

	public void setPkApprovalDefineItem(Long pkApprovalDefineItem) {
		this.pkApprovalDefineItem = pkApprovalDefineItem;
	}

	public ApprovalDefine getApprovalDefine() {
		return approvalDefine;
	}

	public void setApprovalDefine(ApprovalDefine approvalDefine) {
		this.approvalDefine = approvalDefine;
	}

	public Integer getSequenceNumber() {
		return sequenceNumber;
	}

	public void setSequenceNumber(Integer sequenceNumber) {
		this.sequenceNumber = sequenceNumber;
	}

	public AppSideType getAppsidetype() {
		return appsidetype;
	}

	public void setAppsidetype(AppSideType appsidetype) {
		this.appsidetype = appsidetype;
	}

	public Department getApprovalDepartment() {
		return approvalDepartment;
	}

	public void setApprovalDepartment(Department approvalDepartment) {
		this.approvalDepartment = approvalDepartment;
	}

	public Role getApprovalRole() {
		return approvalRole;
	}

	public void setApprovalRole(Role approvalRole) {
		this.approvalRole = approvalRole;
	}

	public User getApprovalUser() {
		return approvalUser;
	}

	public void setApprovalUser(User approvalUser) {
		this.approvalUser = approvalUser;
	}
	
	public ApprovalRuleRegister getApprovalRuleRegister() {
		return approvalRuleRegister;
	}

	public void setApprovalRuleRegister(ApprovalRuleRegister approvalRuleRegister) {
		this.approvalRuleRegister = approvalRuleRegister;
	}
	
	public String getArrKeyValue() {
		return arrKeyValue;
	}

	public void setArrKeyValue(String arrKeyValue) {
		this.arrKeyValue = arrKeyValue;
	}

	public String getArrValue() {
		return arrValue;
	}

	public void setArrValue(String arrValue) {
		this.arrValue = arrValue;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
}
